﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class PlayerManager : MonoBehaviour
{
    public Animator anim;

    // Animator Override Controller
    public AnimatorOverrideController player1;
    public AnimatorOverrideController player2;

    // Game Manager
    public GameManager gameManager;

    // Start is called before the first frame update
    void Start()
    {
        //PlayerPrefs.SetInt("player", 0);

        PlayerPrefsSwitch();

        //Debug.Log(PlayerPrefs.GetInt("player"));
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void PlayerPrefsSwitch()
    {
        int player_index = PlayerPrefs.GetInt("player");

        if(player_index == 0)
        {
            SwitchPlayer1();
        }
        else if(player_index == 1)
        {
            SwitchPlayer2();
        }
    }


    public void SwitchPlayer1()
    {
        anim.runtimeAnimatorController = player1;

        PlayerPrefs.SetInt("player", 0);

        if (Time.timeScale == 0)
        {
            gameManager.OnStart();
        }
    }

    public void SwitchPlayer2()
    {
        anim.runtimeAnimatorController = player2;

        PlayerPrefs.SetInt("player", 1);

        if (Time.timeScale == 0)
        {
            gameManager.OnStart();
        }
    }
}
